package com.april.product.service.impl;

import com.april.common.utils.PageUtils;
import com.april.common.utils.Query;
import com.april.product.entity.BrandEntity;
import com.april.product.mapper.BrandMapper;
import com.april.product.service.BrandService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandMapper, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        boolean isKey = StringUtils.isNotEmpty(key);
        LambdaQueryWrapper<BrandEntity> wrapper = Wrappers.<BrandEntity>lambdaQuery()
                .eq(isKey, BrandEntity::getBrandId, key).or().like(isKey, BrandEntity::getName, key);
        IPage<BrandEntity> page = this.page(new Query<BrandEntity>().getPage(params), wrapper);
        return new PageUtils(page);
    }

}